package model;

public class NextStateCalculator {
	
	
		private CalculateNextLeadStateStrategy leadStrategy;
		private CalculateNextOpportunityStateStrategy opportunityStrategy;
		private CalculateNextContractStateStrategy contractStrategy;
		
		NextStateCalculator() {
			leadStrategy = new CalculateNextLeadStateStrategy();
			opportunityStrategy = new CalculateNextOpportunityStateStrategy();
			contractStrategy = new CalculateNextContractStateStrategy();
		}
		
		public SMSObjectState getNextState(SMSObject smsObject, RuleSelector ruleSelector) {
			CalculateNextStateStrategy strategy = null;
			
			if ((smsObject instanceof Lead)&& !(smsObject.getCurrentState() instanceof Qualified)) {
				strategy = leadStrategy;
			}else if ((smsObject instanceof Lead) && (smsObject.getCurrentState()instanceof Qualified)) {
				strategy = opportunityStrategy;
			}else if ((smsObject instanceof Opportunity)&& !(smsObject.getCurrentState() instanceof Approved)) {
				strategy = opportunityStrategy;
			}else if ((smsObject instanceof Opportunity)&& (smsObject.getCurrentState() instanceof Approved)) {
					strategy = contractStrategy;
			} else if (smsObject instanceof Contract) {
				strategy = contractStrategy;
			}
			return strategy.getNextState(smsObject, ruleSelector);
		}
	}

	

